package collection;

import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class ListDemo {
    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        list.add("one");
        list.add("two");
        list.add("three");
        list.add("four");
        list.add("five");

        Iterator<String> it=list.iterator();
        while (it.hasNext()){
            System.out.println("迭代器"+it.next());
        }

        for (String s:list){
            System.out.println("新循环"+s);
        }

        //E get(int index):获取指定下标所对应的元素
        for (int i=0;i<list.size();i++){
            String s=list.get(i);
            System.out.println("for循环"+s);
        }

        //E set(int index,E e):将给定元素设置到指定位置,返回被替代的元素--一般不接收
        //list.set(2,"six");//将list中下标2的元素设置为six--常规写法
        String old=list.set(2,"six");
        System.out.println("list"+list);
        System.out.println(old);

        String s=list.remove(2);
        System.out.println(s);
        System.out.println(list);

        list.add(3,"seven");
        System.out.println(list);


    }
}
